<template>
    <el-dialog title="修改客户状态" :visible="eStatDialogVisible" width="35%" :before-close="beforeClose">
        <el-form :model="newForm" ref="depForm" label-width="80px">
            <el-form-item label="客户名称" prop="name">
                <el-input v-model="newForm.name" placeholder="请输入客户名称" disabled/>
            </el-form-item>
            <el-form-item label="客户状态">
                <el-select v-model="newForm.status" style="width: 100%">
                    <el-option
                            v-for="(mode,index) in departments"
                            :label="mode"
                            :key="index"
                            :value="index"
                    />
                </el-select>
            </el-form-item>
        </el-form>
        <div class="dialog-footer" slot="footer">
            <el-button type="primary" @click="editStatus">保存</el-button>
            <el-button @click="beforeClose">关闭</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import {patchPCustomerApi} from '@/request/api'
    export default {
        name: "EditStatusDialog",
        props: ['tForm', 'eStatDialogVisible', 'editID'],
        data() {
            return {
                departments: ['潜在客户', '正式客户', '资源池客户', '失败客户', '流失客户'],
                newForm: {},
            }
        },
        watch: {
            tForm(val) {
                if (!val) return
                return this.$set(this, 'newForm',{...val})
            }
        },
        methods: {
            beforeClose() {
                this.$refs['depForm'].resetFields()
                this.$emit('closeSDialog')
            },
            editStatus() {
                patchPCustomerApi({
                    id:this.editID,
                    customerId: this.editID,
                    name: this.newForm.name,
                    status: this.newForm.status,
                }).then(res => {
                    if (res.success === true) {
                        this.$refs['depForm'].resetFields()
                        this.$emit('closeSDialog', true)
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>